/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package services;

import dao.UserStatsJpaController;
import entities.User;
import entities.UserStats;

public class UserStatsService {
    private static UserStatsJpaController usc;

    private UserStatsJpaController getJPAController()
    {
        if(usc == null)
            usc = new UserStatsJpaController();
        return usc;
    }

    public UserStats saveUserStats()
    {
        usc = getJPAController();
        UserStats stats = new UserStats();
        try
        {
            usc.create(stats);
        }
        catch (Exception e)
        {
            return null;
        }
        return stats;
    }
    public UserStats getUserStats(Integer id)
    {
        usc = getJPAController();
        return usc.findUserStats(id);
    }

    public boolean deleteUserStats(UserStats c)
    {
        usc = getJPAController();
        try
        {
            usc.destroy(c.getIdUserStats());
            return true;
        }
        catch (Exception e)
        {
            return false;
        }
    }

    public UserStats getStatsByUser(User u)
    {
        usc = getJPAController();
        try
        {
            return usc.findByUser(u);
        } catch (Exception e)
        {
            return null;
        }
    }
}
